Skip to content

Don't include HTTP headers from GitHub API request in redirected artifact download request #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2024
Merged

Conversation

per1234
Copy link
Collaborator

@per1234 per1234 commented Jan 24, 2024

In the use case where the arduino/report-size-deltas action is ran from a GitHub Actions workflow triggered by a schedule event, it downloads the sketches report file from a workflow artifact.

The GitHub REST API is used to perform this artifact download. The artifact download process is:

  1. Action sends request to /repos/{owner}/{repo}/actions/artifacts/{artifact_id}/{archive_format} endpoint
  2. API responds with HTTP 302 status
  3. Action sends request to temporary file download URL provided by the API response
  4. Artifact file is downloaded

The API request at step (1) must be authenticated using a GitHub access token. This token is passed via the Authorization HTTP header in the request.

No authentication is required for the download request at step (3).

The urllib.request Python module is used to perform the HTTP requests. By default, this module passes the headers from the original request to the redirect request.

Although these headers were superfluous, they didn't affect the download request when the target artifact was of the v1 format generated by version 3.x and earlier of the actions/upload-artifact action. A new v2 artifact format was introduced in the 4.0.0 release of the actions/upload-artifact action. Previously, the request at step (3) of the artifact download procedure would fail when the target artifact had the v2 format:

https://github.com/arduino/report-size-deltas/actions/runs/7633691244/job/20796387110#step:3:164

urllib.error.HTTPError: HTTP Error 400: Authentication information is not given in the correct format. Check the value of Authorization header.
Error: HTTPError: HTTP Error 400: Authentication information is not given in the correct format. Check the value of Authorization header.
<?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidAuthenticationInfo</Code><Message>Authentication information is not given in the correct format. Check the value of Authorization header.

RequestId:1f13170a-001e-0076-5f5d-4e8d15000000

Time:2024-01-24T00:35:22.8264229Z</Message></Error>

The cause of the failure was the inclusion of the Authorization HTTP header in the download request. The urllib.request Python module can be configured to pass a header in the original request but not in the redirected request by defining the header via the Request.add_unredirected_header method instead of in the Request instantiation. This provides compatibility for using the action with v2 format artifacts.

…fact download request

In the use case where the "arduino/report-size-deltas" action is ran from a GitHub Actions workflow triggered by a
`schedule` event, it downloads the sketches report file from a workflow artifact.

The GitHub REST API is used to perform this artifact download. The artifact download process is:

1. Action sends request to `/repos/{owner}/{repo}/actions/artifacts/{artifact_id}/{archive_format}` endpoint
2. API responds with HTTP 302 status
3. Action sends request to temporary file download URL provided by the API response
4. Artifact file is downloaded

The API request at step (1) must be authenticated using a GitHub access token. This token is passed via the
`Authorization` HTTP header in the request.

No authentication is required for the download request at step (3).

The `urllib.request` Python module is used to perform the HTTP requests. By default, this module passes the headers from
the original request to the redirect request.

Although these headers were superfluous, they didn't affect the download request when the target artifact was of the v1
format generated by version 3.x and earlier of the "actions/upload-artifact" action. A new v2 artifact format was
introduced in the 4.0.0 release of the "actions/upload-artifact" action. Previously, the request at step (3) of the
artifact download procedure would fail when the target artifact had the v2 format:

```
urllib.error.HTTPError: HTTP Error 400: Authentication information is not given in the correct format. Check the value of Authorization header.
Error: HTTPError: HTTP Error 400: Authentication information is not given in the correct format. Check the value of Authorization header.
<?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidAuthenticationInfo</Code><Message>Authentication information is not given in the correct format. Check the value of Authorization header.

RequestId:1f13170a-001e-0076-5f5d-4e8d15000000

Time:2024-01-24T00:35:22.8264229Z</Message></Error>
```

The cause of the failure was the inclusion of the `Authorization` HTTP header in the download request. The
`urllib.request` Python module can be configured to pass a header in the original request but not in the redirected
request by defining the header via the `Request.add_unredirected_header` method instead of in the `Request`
instantiation. This provides compatibility for using the action with v2 format artifacts.
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Jan 24, 2024
@per1234 per1234 self-assigned this Jan 24, 2024
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (57289ee) 100.00% compared to head (d590a75) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #83   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          745       752    +7     
=========================================
+ Hits           745       752    +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants